/**
 * Created by Administrator on 2015/11/17.
 */
$(function(){
    $(".updpwdbt").click(function(){
        $(".modelbg").show();
        $(".updpwdbox").show();
    })
})
function updpwd(){
    var oldpwd   = $(".updpwdbox").find("input[name=oldpwd]").val();
    var newpwd  = $(".updpwdbox").find("input[name=newpwd]").val();
    var surenewpwd  = $(".updpwdbox").find("input[name=surenewpwd]").val();
    $.ajax({
        type:"post",
        url:"returnTrue.json",//�˴�����true��false
        dataType:"json",
        data:{"oldpwd":oldpwd,"newpwd":newpwd,"surenewpwd":surenewpwd},
        success:function(data){
            if(data.success){
                $(".modelbg").hide();
                $(".updpwdbox").hide();
                $(".updpwdbox").find("input[name=oldpwd]").val("");
                $(".updpwdbox").find("input[name=newpwd]").val("");
                $(".updpwdbox").find("input[name=surenewpwd]").val("");
            }
        }
    })
}
//�ر��޸�����
function closeupdpwd(){
    $(".modelbg").hide();
    $(".updpwdbox").hide();
    $(".updpwdbox").find("input[name=oldpwd]").val("");
    $(".updpwdbox").find("input[name=newpwd]").val("");
    $(".updpwdbox").find("input[name=surenewpwd]").val("");
}

//添加病人
function openAddPerson(){
	 $("#patientid").val("");
     $(".addpersonbox").find("input[name=name]").val("");//病人姓名
   //$(".addpersonbox").find("input[name=sex][value="+data.sex+"]").click();//性别
     $(".addpersonbox").find("input[name=age]").val("");//年龄
   $(".addpersonbox").find("input[name=roomtime]").val("");//入院时间
   $(".addpersonbox").find("input[name=sicknum]").val("");//所患疾病
    $(".addpersonbox").find("input[name=sickname]").val("");//所患疾病
    $(".addpersonbox").find("input[name=doctor]").val("");//主管医生
    //$(".addpersonbox").find("input[name=roomid]").val("");//病房号
   $(".addpersonbox").find("input[name=bedid]").val("");//病床号
   $("#idofbed").val("");//病床id
    $(".addpersonbox").find("input[name=cardname]").val("");//贴片号码
   $(".addpersonbox").find("input[name=highNY]").val("2500");//温度监控范围 最低温度
   $(".addpersonbox").find("input[name=lowNY]").val("2000");//温度监控范围 最高温度superHighDegree
   $(".addpersonbox").find("input[name=samplingTime]").val("");
   //$(".addpersonbox").find("input[name=count]").val(data.count);//温度采集间隔数字
    $(".addpersonbox").find("input[name=sicktype]").val("");//就医类型
   $(".addpersonbox").find("input[name=personid]").val("");//身份证
   $(".addpersonbox").find("input[name=address]").val("");//地址
   //$("#title").text("添加病人");
    $('.addpersonbox').show();$('.modelbg').show()
}

//��Ӳ��˹���
function sureAddPersonCom(){
//    var nowbedId = $(nowAddPersonBed).attr("id");//��ǰ��ӵĲ���ID
	var patientid = $("#patientid").val();//��ǰ��ӵĲ���ID
	var idofbed=$("#idofbed").val();

    var name = $(".addpersonbox").find("input[name=name]").val();//��������
    var sex = $(".addpersonbox").find("input[name=sex]:checked").val();//�Ա�
    var age = $(".addpersonbox").find("input[name=age]").val();//����
    var roomtime = $(".addpersonbox").find("input[name=roomtime]").val();//��Ժʱ��
    var sicknum = $(".addpersonbox").find("input[name=sicknum]").val();
    var sickname = $(".addpersonbox").find("input[name=sickname]").val();//����
    var doctor = $(".addpersonbox").find("input[name=doctor]").val();//����ҽ��
    var roomid = $(".addpersonbox").find("input[name=roomid]").val();//������
    var bedid = $(".addpersonbox").find("input[name=bedid]").val();//������
    var cardname = $(".addpersonbox").find("input[name=cardname]").val();//��Ƭ����
    var highNY = parseInt($(".addpersonbox").find("input[name=highNY]").val());//�¶ȼ�ط�Χ ����¶�
    var lowNY = parseInt($(".addpersonbox").find("input[name=lowNY]").val());//�¶ȼ�ط�Χ ����¶�
    //var superHighDegree = $(".addpersonbox").find("input[name=superHighDegree]").val();
    var samplingTime= $(".addpersonbox").find("input[name=samplingTime]").val();
    var count = $(".addpersonbox").find("input[name=count]").val();//�¶Ȳɼ��������
    var sicktype = $(".addpersonbox").find("input[name=sicktype]").val();//��ҽ����
    var personid = $(".addpersonbox").find("input[name=personid]").val();//���֤
    var address = $(".addpersonbox").find("input[name=address]").val();//��
    var startTime = new Date(roomtime.replace(/-/g,"/") );
if(roomtime.trim()=="")startTime =new Date();
	//startTime =new Date();
//alert(startTime);return;
    //验证表单数据是否符合规则
    if(cardname.length!=12) {
    	layer.alert('请检查贴片号码是否正确！');
    	return;
    }
    if(lowNY>highNY){
    	layer.alert('温度填写错误！');//, {icon: 6});
    }
    
    if(age){
    	if(isNaN(age)){
    		layer.alert("年龄必须为数字！");
     	}
    }
    
    
    //if(roomtime==null||roomtime.length==0) {alert('请正确填写入院时间');return;}
    var paras={"medicalTreatmentType":sicktype,"personnelId":personid,"address":address,"id":patientid,"name":name,"sex":sex,"age":age,"bedName":bedid,//"bed.id":idofbed,"startTime":startTime,
        	"medicalRecordNumber":sicknum,"disease":sickname,"doctor":doctor,"equipNo":cardname,"highNY":highNY,"lowNY":lowNY,"samplingTime":samplingTime,"startTime":startTime,"userId":""+$("#user_attr_id").val()+""}

    if(patientid.length==0) {
paras={"medicalTreatmentType":sicktype,"personnelId":personid,"address":address,"name":name,"sex":sex,"age":age,"bedName":bedid,
    		"medicalRecordNumber":sicknum,"disease":sickname,"doctor":doctor,"equipNo":cardname,"highNY":highNY,"lowNY":lowNY,"samplingTime":samplingTime,"startTime":startTime,"userId":""+$("#user_attr_id").val()+""}
}
    console.log(paras);
    if(bedid.length==0) {layer.alert('请填写 病床号');return;}
    $.ajax({
        type:"post",
        url:"../patient/save.action",//��Ӳ�����Ϣ
        dataType:"json",
        data:paras,//{"medicalTreatmentType":sicktype,"personnelId":personid,"address":address,"id":patientid,"name":name,"sex":sex,"age":age,"bedName":bedid,//"bed.id":idofbed,
        	//"disease":sickname,"doctor":doctor,"equipNo":cardname,"rangeEnd":highc,"rangeStart":lowc,"startTime":startTime},
        //data:{"medicalTreatmentType":sicktype,"personnelId":personid,"address":address,"id":patientid,"name":name,"sex":sex,"age":age,"startTime":roomtime,
        	//"disease":sickname,"doctor":doctor,"equipNo":cardname,"rangeEnd":highc,"rangeStart":lowc},//,"bed_id":idofbed//2015-11-28 10:01:43
        success:function(data){
        	if(data.success == false){ 
        		//alert(data.bedstatus);
        		layer.alert("添加失败，请重试！");
				return;
			}
            $('.addpersonbox').hide();
            $('.modelbg').hide();
            //location.reload(true);
            if(nowPageType==0){
            	getBedsData();
            }else{
            	getPatientListData();
            }
        }

    })
}